package com.example.demos.web.controller;


import com.example.demos.entity.MarketDetail;
import com.example.demos.service.MarketDetailService;
import com.example.demos.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.math.BigInteger;

@RestController
@RequestMapping("/v2/marketdetail")
public class MarketDetailController {

    @Autowired
    private MarketDetailService marketDetailService;

    @PostMapping("/doOutStore")
    public Result<Void> updateMarketDetailState(@RequestParam("id") BigInteger marketDetailId,
                                                @RequestParam("storeuuid") BigInteger storeUuid,
                                                HttpSession session) {
        int i = marketDetailService.updateMarketDetailState(marketDetailId, storeUuid, session);
        if (i > 0) {
            return Result.ok("商品出库成功");
        } else if (i == -1) {
            return Result.bizErr("库存不足");
        } else if (i == -2) {
            return Result.bizErr("仓库没有这个商品");
        } else {
            return Result.bizErr("商品出库失败");
        }
    }


}
